///@file Particle.cpp source file for class CParticle
///@author	charlie Tan: gths123@gmail.com
#include "ISceneManager.h"
#include "Particle.h"

//! sharpShooter
namespace sharpShooter
{
	//! Scene
	namespace Scene
	{

		CParticle::CParticle(ISceneNode* parent, ISceneManager* smgr,Core::Vector2f size, Render::TexturePtr texture,
			Core::Vector3f startposition, Core::Vector3f startvelocity, double startTime, float lifespan, Core::Vector3f gravity)
			:m_StartPosition(startposition),m_StartVelocity(startvelocity),m_StartTime(startTime),m_LifeSpan(lifespan),m_Gravity(gravity),
			CBillboardSceneNode(parent,smgr,startposition,size/*,texture*/)
		{

		}

		void CParticle::update(double nowTime)
		{
			double elapsedTime = fmod((nowTime - m_StartTime) , m_LifeSpan);
			m_Position = m_StartPosition + (m_StartVelocity * ((float)elapsedTime)) + (m_Gravity * ((float)elapsedTime) * ((float)elapsedTime/2));
		}

		void CParticle::render(/*ID3DXEffect *effect*/)
		{
			CBillboardSceneNode::render(/*effect*/);
		}

		Core::Vector3f CParticle::getVelocity(void)
		{
			return m_Velocity;
		}
		void CParticle::setVelocity(Core::Vector3f velocity)
		{
			m_Velocity = velocity;
		}

		Core::Vector3f CParticle::getStartVelocity(void)
		{
			return m_StartVelocity;
		}
		void CParticle::setStartVelocity(Core::Vector3f startVelocity)
		{
			m_StartVelocity = startVelocity;
		}

		Core::Vector3f CParticle::getGravity(void)
		{
			return m_Gravity;
		}
		void CParticle::setGravity(Core::Vector3f gravity)
		{
			m_Gravity = gravity;
		}

		double CParticle::getLifeSpan(void)
		{
			return m_LifeSpan;
		}
		void CParticle::setLifeSpan(double lifespan)
		{
			m_LifeSpan = lifespan;
		}

		double CParticle::getStartTime(void)
		{
			return m_StartTime;
		}
		void CParticle::setStartTime(double startTime)
		{
			m_StartTime = startTime;
		}

		Core::Vector3f CParticle::getStartPosition(void)
		{
			return m_StartPosition;
		}
		void CParticle::setStartPosition(Core::Vector3f position)
		{
			m_StartPosition = position;
		}

	}
}